import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../ObjCreate";
import { TextBox } from "../../pack/TextBox";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { UICompomentPool } from "../../../../../com/mui/utils/UICompomentPool";
import { GTextFormat } from "../../../../common/GTextFormat";
import { AutoGuideClickChildNames } from "../guide/AutoGuideClickChildNames";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
type int = number;
//class PageSelecter
    
    export  class PageSelecter extends GSprite
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            this._firstPageBtn.dispose();
            this._prevPageBtn.dispose();
            this._pageText.dispose();
            this._nextPageBtn.dispose();
            this._lastPageBtn.dispose();
            this._tiPage.dispose();
            this._btnJump.dispose();
            this._tf1.dispose();
            this._tf2.dispose();
            ObjCreate.disposeSprite(this._spInputContainer);
            this._firstPageBtn = null;
            this._prevPageBtn = null;
            this._pageText = null;
            this._nextPageBtn = null;
            this._lastPageBtn = null;
            this._tiPage = null;
            this._btnJump = null;
            this._tf1 = null;
            this._tf2 = null;
            this._spInputContainer = null;
            super.disposeImpl(arg1);
            return;
        }

        protected drawNow(): void
        {
            this.removeAll();
            var loc1=new Vector.<flash.display.DisplayObject>();
            if (this._mode == PageSelecter.CompleteMode || this._mode == PageSelecter.InputMode) 
            {
                loc1.push(this._firstPageBtn);
                loc1.push(this._prevPageBtn);
                loc1.push(this._pageText);
                loc1.push(this._nextPageBtn);
                loc1.push(this._lastPageBtn);
                if (this._mode == PageSelecter.InputMode) 
                {
                    loc1.push(this._spInputContainer);
                }
            }
            else 
            {
                loc1.push(this._prevPageBtn);
                loc1.push(this._pageText);
                loc1.push(this._nextPageBtn);
            }
            var loc2=0;
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                loc1[loc3].x = loc2;
                loc1[loc3].y = loc1[loc3] is TextBox ? 1 : 0;
                loc2 = loc2 + (loc1[loc3].width + 1);
                if (typeof loc1[loc3] === "gbutton") 
                {
                    (loc1[loc3] as GButton).drawNow();
                }
                this.addChild(loc1[loc3]);
                ++loc3;
            }
            return;
        }

        protected removeAll(): void
        {
            var loc1=this.numChildren;
            var loc2;
            --loc2;
            while (loc2 >= 0) 
            {
                this.removeChildAt(loc2);
                --loc2;
            }
            return;
        }

        protected prevPage(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.gotoPage((this._currentPage - 1));
            return;
        }

        protected nextPage(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.gotoPage(this._currentPage + 1);
            return;
        }

        protected firstPage(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.gotoPage(1);
            return;
        }

        protected lastPage(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.gotoPage(this._maxPage);
            return;
        }

        protected tiChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=int(this._tiPage.text);
            loc1 = loc1 > this.maxPage ? this.maxPage : loc1;
            loc1 = loc1 < 1 ? 1 : loc1;
            this._tiPage.text = loc1.toString();
            return;
        }

        protected onJump(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.gotoPage(int(this._tiPage.text));
            return;
        }

        protected gotoPage(arg1: int): void
        {
            arg1 = arg1 < 1 ? 1 : arg1;
            arg1 = arg1 > this._maxPage ? this._maxPage : arg1;
            if (this._currentPage != arg1) 
            {
                this._currentPage = arg1;
                this.dispatchEvent(new Object /* flash.events.Event */(flash.events.Event.CHANGE, true));
                this.updateText();
            }
            return;
        }

        public get mode(): string
        {
            return this._mode;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            this.drawNow();
            return;
        }

        public get pageTextBoxSize(): int
        {
            return this._pageTextBoxSize;
        }

        public set pageTextBoxSize(arg1: int)
        {
            this._pageTextBoxSize = arg1;
            this._pageText.bgWidth = this._pageTextBoxSize;
            this.drawNow();
            return;
        }

        public get maxPage(): int
        {
            return this._maxPage;
        }

        public set maxPage(arg1: int)
        {
            this._maxPage = arg1;
            if (this._maxPage <= 0) 
            {
                this._maxPage = 1;
            }
            if (this._currentPage > this._maxPage) 
            {
                this._currentPage = this._maxPage;
            }
            if (this._pageText) 
            {
                this.updateText();
            }
            return;
        }

        public get currentPage(): int
        {
            return this._currentPage;
        }

        public set currentPage(arg1: int)
        {
            this._currentPage = arg1 > 0 ? arg1 : 1;
            this._currentPage = arg1 < this.maxPage ? this._currentPage : this.maxPage;
            if (this._pageText) 
            {
                this.updateText();
            }
            return;
        }

        public move(arg1: number, arg2: number): void
        {
            this.x = arg1;
            this.y = arg2;
            return;
        }

        public updatePageTxt(arg1: int): void
        {
            this.gotoPage(arg1);
            return;
        }

        protected updateText(): void
        {
            this._pageText.textField.text = this._currentPage + "/" + this._maxPage;
            this._nextPageBtn.enabled = this.currentPage < this.maxPage;
            this._prevPageBtn.enabled = this.currentPage > 1;
            this._firstPageBtn.enabled = this.currentPage > 1;
            this._lastPageBtn.enabled = this.currentPage < this.maxPage;
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            this._firstPageBtn = ObjCreate.createGButton("", 0, 0, 21, 20, this, "FirstPageButton");
            this._firstPageBtn.configEventListener(flash.events.MouseEvent.CLICK, this.firstPage);
            this._prevPageBtn = ObjCreate.createGButton("", 0, 0, 21, 20, this, "PrevPageButton");
            this._prevPageBtn.configEventListener(flash.events.MouseEvent.CLICK, this.prevPage);
            this._pageText = UICompomentPool.getUICompoment(TextBox) as TextBox;
            this._pageText.createDisposedChildren();
            this._pageText.bgWidth = this._pageTextBoxSize;
            this._pageText.bgHeight = 18;
            this._pageText.htmlText = "";
            var loc1=new GTextFormat();
            loc1.color = 1048575;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._pageText.textField.defaultTextFormat = loc1;
            this.addChild(this._pageText);
            this._nextPageBtn = ObjCreate.createGButton("", 0, 0, 21, 20, this, "NextPageButton");
            this._nextPageBtn.configEventListener(flash.events.MouseEvent.CLICK, this.nextPage);
            this._nextPageBtn.name = AutoGuideClickChildNames.PageSelector_BtnNextName;
            this._lastPageBtn = ObjCreate.createGButton("", 0, 0, 21, 20, this, "LastPageButton");
            this._lastPageBtn.configEventListener(flash.events.MouseEvent.CLICK, this.lastPage);
            this._spInputContainer = UICompomentPool.getUICompoment(flash.display.Sprite) as Object /* flash.display.Sprite */;
            this._tf1 = ObjCreate.createGTextField(Language.getString(41614), 0, 2, 30, 20, this._spInputContainer, GlobalStyle.textFormat2);
            this._tiPage = ObjCreate.createGTextInput(30, 1, 75, 20, this._spInputContainer);
            this._tiPage.restrict = "0-9";
            this._tf2 = ObjCreate.createGTextField(Language.getString(41615), 107, 2, 18, 20, this._spInputContainer, GlobalStyle.textFormat2);
            this._btnJump = ObjCreate.createGButton(Language.getString(41616), 125, -1, 59, 22, this._spInputContainer);
            this._tiPage.configEventListener(flash.events.Event.CHANGE, this.tiChangeHandler);
            this._btnJump.configEventListener(flash.events.MouseEvent.CLICK, this.onJump);
            this.drawNow();
            this.updateText();
            return;
        }

        public static /* const */SingleMode: string="简单状态";

        public static /* const */CompleteMode: string="完整状态";

        public static /* const */InputMode: string="带输入框的状态";

        protected /* var */_mode: string="简单状态";

        protected /* var */_firstPageBtn: GButton;

        protected /* var */_prevPageBtn: GButton;

        protected /* var */_pageText: TextBox;

        protected /* var */_nextPageBtn: GButton;

        protected /* var */_lastPageBtn: GButton;

        protected /* var */_spInputContainer: Object /* flash.display.Sprite */;

        protected /* var */_tf1: GTextFiled;

        protected /* var */_tf2: GTextFiled;

        protected /* var */_tiPage: GTextInput;

        protected /* var */_btnJump: GButton;

        protected /* var */_currentPage: int=1;

        protected /* var */_maxPage: int=1;

        protected /* var */_pageTextBoxSize: int=36;
    }
